﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using sgsBase;

namespace TestApp.Account
{
    public partial class Login : SgsPage
    {
        protected override void PageLoad(object sender, EventArgs e)
        {
            RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
        }

		protected void LoginButton_Clicked(object sender, EventArgs e)
		{
			bool authenticated = false;
			authenticated = Gl.CurUser.Login(UserName.Text, Password.Text);
			if (authenticated)
			{
				if (RememberMe.Checked)
				{
					HttpCookie cookie= new HttpCookie(ApplicationHelper.CookieGroup);
					cookie[ApplicationHelper.LoginCookie] = Gl.CurUser.CreateLoginCookie();
					cookie.Expires = DateTime.Now.AddYears(1);
					Response.Cookies.Add(cookie); 
				}
				//FormsAuthentication.SetAuthCookie(LoginUser.UserName, true);
				Response.Redirect("~/default.aspx");
			} 
			else 
				{ //FormsAuthentication.SetAuthCookie(UserName.Text, false); 
				} 
			
			//Response.Redirect("/members"); } else { Response.Redirect("/login?lif=true"); 

		}
    }
}
